package lab6.systemCustom;

import java.util.ArrayList;
import java.util.StringTokenizer;

@SuppressWarnings("unchecked")
public class Course {

	protected String sCID;

	protected String sDays;

	protected int iStart;

	protected int iStop;

	protected String sInstructor;

	protected String sName;

	protected ArrayList vRegistered;

	public Course(String sInput) {
		StringTokenizer objTokenizer = new StringTokenizer(sInput);

		this.sCID = objTokenizer.nextToken();
		this.sDays = objTokenizer.nextToken();
		this.iStart = Integer.parseInt(objTokenizer.nextToken());
		this.iStop = Integer.parseInt(objTokenizer.nextToken());
		this.sInstructor = objTokenizer.nextToken();

		this.sName = objTokenizer.nextToken();
		while (objTokenizer.hasMoreTokens()) {
			this.sName = this.sName + " " + objTokenizer.nextToken();
		}

		this.vRegistered = new ArrayList();
	}

	public boolean match(String sCID) {
		return this.sCID.equals(sCID);
	}

	public boolean conflicts(Course objCourse) {
		if (this.sCID.equals(objCourse.sCID)) {
			return true;
		}

		for (int i = 0; i < this.sDays.length(); i++) {
			for (int j = 0; j < objCourse.sDays.length(); j++) {
				if (this.sDays.regionMatches(i, objCourse.sDays, j, 1)) {
					return (this.iStart <= objCourse.iStart && objCourse.iStart < this.iStop)
							|| (objCourse.iStart <= this.iStart && this.iStart < objCourse.iStop) ? true : false;
				}
			}
		}
		return false;
	}

	public String getName() {
		return this.sName;
	}

	public ArrayList getRegisteredStudents() {
		return this.vRegistered;
	}

	public void registerStudent(Student objStudent) {
		this.vRegistered.add(objStudent);
	}

	public String toString() {
		return this.sCID + " " + this.sDays + " " + this.iStart + " " + this.iStop + " " + this.sInstructor + " " + this.sName;
	}

}